// hyb_yl/qianyue/qianyue.js
var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    var that = this
    var openid = options.openid
    console.log(options)
    var zid = options.zid
    app.util.request({
      'url': "entry/wxapp/Myinforsarray",
      data: {
        openid: openid,
      },
      success: function(res) {
        console.log(res)
        that.setData({
          myinforsarray: res.data.data,
          touxiang: res.data.data.u_thumb
        })
      },
      fail: function(err) {
        console.log(err)
      },
    })
    var bgc = wx.getStorageSync('color');
    wx.setNavigationBarColor({
      frontColor: "#ffffff",
      backgroundColor: bgc,
    })
    that.setData({
      openid: openid,
      zid: zid
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  tongyibtn: function(e) {
    console.log(e)
    var that = this
    var formId = e.detail.formId
    var useropenid = that.data.openid
    var docopenid = wx.getStorageSync('openid')
    var zid = that.data.zid
    console.log(zid)
    //发送模板消息已同意
    app.util.request({
      'url': 'entry/wxapp/UserFormId',
      'data': {
        form_id: formId,
        openid: docopenid
      },
      success: function(res) {
        app.util.request({
          'url': 'entry/wxapp/docqianyuetix',
          method: "GET",
          data: {
            openid: useropenid,
            zid: zid,
            op: 'tongyi'
          },
          success: function(res) {
            console.log(res)
            wx.showToast({
              title: '您已经同意',
              icon: "none",
              duration: 1500,
              success: function(res) {
                setTimeout(function() {
                  wx.redirectTo({
                    url: '/hyb_yl/tabBar/index/index',
                  })
                },2000)
              }
            })
          }
        })
      }
    })

  },
  jujuebtn: function(e) {
    console.log(e)
    var that = this
    var formId = e.detail.formId
    var useropenid = that.data.openid
    var docopenid = wx.getStorageSync('openid')
    var zid = that.data.zid
    console.log(zid)
    //发送模板消息已同意
    app.util.request({
      'url': 'entry/wxapp/UserFormId',
      'data': {
        form_id: formId,
        openid: docopenid
      },
      success: function (res) {
        app.util.request({
          'url': 'entry/wxapp/docqianyuetix',
          method: "GET",
          data: {
            openid: useropenid,
            zid: zid,
            op: 'jujue'
          },
          success: function (res) {
            console.log(res)
            wx.showToast({
              title: '您已经拒绝',
              icon: "none",
              duration: 1500,
              success: function (res) {
                setTimeout(function () {
                  wx.redirectTo({
                    url: '/hyb_yl/tabBar/index/index',
                  })
                }, 2000)
              }
            })
          }
        })
      }
    })
  }
})